<?php

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * View class
 */
class TaxiBookingViewOrder extends JView {

	function display($tpl = null)
	{
		global $mainframe;

		//Load pane behavior
		jimport('joomla.html.pane');

		//initialise variables
		$editor 	= & JFactory::getEditor();
		$document	= & JFactory::getDocument();
		$user 		= & JFactory::getUser();
		$db  		= & JFactory::getDBO();
		$lang 		= & JFactory::getLanguage();
		$pane 		= & JPane::getInstance('sliders');

		JHTML::_('behavior.tooltip');

		$nullDate 		= $db->getNullDate();

		//get vars
		$cid 		= JRequest::getVar( 'cid' );


		//Get data from the model
		$model		= & $this->getModel();
		$row     	= & $this->get( 'Item' );
                $row_paypal    	= & $this->getPaypalData($row);
                
                if(!empty($row_paypal)){
                    $row->prepay = ceil($row_paypal->mc_gross*$row->cprice/100);
                }else{
                    $row->prepay = 0;                    
                }
	
		//build selectlists
		$lists = array();
		
		//build state list
		$state[] = JHTML::_('select.option',  1, JText::_( 'Accepted' ) );
		$state[] = JHTML::_('select.option',  0, JText::_( 'Rejected' ) );
		$state[] = JHTML::_('select.option',  -1, JText::_( 'Archived' ) );
		$state[] = JHTML::_('select.option',  -2, JText::_( 'Waiting' ) );

		$lists['state'] = JHTML::_('select.genericlist',   $state, 'state', '', 'value', 'text', $row->state );

		//assign data to template
		$this->assignRef('lists'      	, $lists);
		$this->assignRef('row_queue'      	, $row);
                $this->assignRef('row_paypal'      	, $row_paypal);
		$this->assignRef('editor'		, $editor);
		$this->assignRef('pane'			, $pane);
		$this->assignRef('nullDate'		, $nullDate);

		parent::display($tpl);
	}
        
        /**
	 * Method to load paypal data
	 *
	 * @access	private
	 * @return	boolean	True on success
	 * @since	1.0
	 */
	function &getPaypalData($row)
	{
            $db		= & JFactory::getDBO();
            $item = array ();
            
            if ($row->payment == 'paypal'){
                $query = 'SELECT *'
                        . ' FROM #__taxibooking_paypal_table'
                        . ' WHERE item_number = "'.$row->confirm.'"'
                        ;
                $db->setQuery($query);
                $item = $db->loadObject();
            }

            return $item;
	}
}
?>